{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.2"
    },
    "colab": {
      "name": "XLNet.ipynb",
      "provenance": [],
      "include_colab_link": true
    },
    "accelerator": "GPU",
    "widgets": {
      "application/vnd.jupyter.widget-state+json": {
        "a7b59325aa0540b19139d91e33fb1c0b": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "state": {
            "_view_name": "HBoxView",
            "_dom_classes": [],
            "_model_name": "HBoxModel",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "box_style": "",
            "layout": "IPY_MODEL_20d030310fc54c7dbc2ad67a87a76891",
            "_model_module": "@jupyter-widgets/controls",
            "children": [
              "IPY_MODEL_ad2f49ce511647ca8e75a0734980341b",
              "IPY_MODEL_d6cb4d66ca364da1ac13e2f6b830bb54"
            ]
          }
        },
        "20d030310fc54c7dbc2ad67a87a76891": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "ad2f49ce511647ca8e75a0734980341b": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_33192ad6d500451999ba5ba672d2fff5",
            "_dom_classes": [],
            "description": "models/ProtXLNet/pytorch_model.bin: 100%",
            "_model_name": "FloatProgressModel",
            "bar_style": "success",
            "max": 1637757076,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 1637757076,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_74e103eeb38d493095acd6dbf4b4788c"
          }
        },
        "d6cb4d66ca364da1ac13e2f6b830bb54": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_e49b133233374e1985361c2ac900ae96",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": " 1.53G/1.53G [00:55&lt;00:00, 29.3MB/s]",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_84c9f44c83fc4bc09a2e418bdc95f399"
          }
        },
        "33192ad6d500451999ba5ba672d2fff5": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "initial",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "74e103eeb38d493095acd6dbf4b4788c": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "e49b133233374e1985361c2ac900ae96": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "84c9f44c83fc4bc09a2e418bdc95f399": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "a497f90d042949cea815f05b21d29ef2": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "state": {
            "_view_name": "HBoxView",
            "_dom_classes": [],
            "_model_name": "HBoxModel",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "box_style": "",
            "layout": "IPY_MODEL_06dc2479b6f749c99f8e18c545e29336",
            "_model_module": "@jupyter-widgets/controls",
            "children": [
              "IPY_MODEL_15d2b7fe5b4148ea8b7dd984db82ffee",
              "IPY_MODEL_e1d577e3328f4a88b6c71c52db39c8fb"
            ]
          }
        },
        "06dc2479b6f749c99f8e18c545e29336": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "15d2b7fe5b4148ea8b7dd984db82ffee": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_f71ea8387dfa487f943e13fb6833f44f",
            "_dom_classes": [],
            "description": "models/ProtXLNet/config.json: 100%",
            "_model_name": "FloatProgressModel",
            "bar_style": "success",
            "max": 1351,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 1351,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_ce64e85961b94743bf092d30d889dc71"
          }
        },
        "e1d577e3328f4a88b6c71c52db39c8fb": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_f204f3aec2024cf993c2e60b4e5fe6b6",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": " 1.32k/1.32k [00:07&lt;00:00, 192B/s]",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_f228635787c249a297a352531a8e9b94"
          }
        },
        "f71ea8387dfa487f943e13fb6833f44f": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "initial",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "ce64e85961b94743bf092d30d889dc71": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "f204f3aec2024cf993c2e60b4e5fe6b6": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "f228635787c249a297a352531a8e9b94": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "d5be147b7cd74ad18a97b0fce1228144": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "state": {
            "_view_name": "HBoxView",
            "_dom_classes": [],
            "_model_name": "HBoxModel",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "box_style": "",
            "layout": "IPY_MODEL_a3ccc2e62231425dbdf6350f55c47c7d",
            "_model_module": "@jupyter-widgets/controls",
            "children": [
              "IPY_MODEL_d16c310cb93245ba8af3802e57d8d477",
              "IPY_MODEL_93692c6334a34411bcc9319d4303d42e"
            ]
          }
        },
        "a3ccc2e62231425dbdf6350f55c47c7d": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "d16c310cb93245ba8af3802e57d8d477": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_df1215a1a78c451b8637be18dea4b1dd",
            "_dom_classes": [],
            "description": "models/ProtXLNet/spm_model.model: 100%",
            "_model_name": "FloatProgressModel",
            "bar_style": "success",
            "max": 238192,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 238192,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_48be69984d59411ea99c0dcd599c7b36"
          }
        },
        "93692c6334a34411bcc9319d4303d42e": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_8f492bf7ab29454c837579b5e17273c8",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": " 233k/233k [00:00&lt;00:00, 904kB/s]",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_b1d69142187c4f38b57bbba9f93d9979"
          }
        },
        "df1215a1a78c451b8637be18dea4b1dd": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "initial",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "48be69984d59411ea99c0dcd599c7b36": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "8f492bf7ab29454c837579b5e17273c8": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "b1d69142187c4f38b57bbba9f93d9979": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        }
      }
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/agemagician/Prot-Transformers/blob/master/Benchmark/XLNet.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "zBFpzzE-PWdN",
        "colab_type": "text"
      },
      "source": [
        "<h3> Benchmark ProtXLNet Model using GPU or CPU <h3>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2FXhG9kNPWdQ",
        "colab_type": "text"
      },
      "source": [
        "<b>1. Load necessry libraries including huggingface transformers<b>"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "6kmQPwqCPdyz",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 102
        },
        "outputId": "54f1dcc5-1e3b-4245-afb4-efa44c5ba9bb"
      },
      "source": [
        "!pip install -q transformers"
      ],
      "execution_count": 1,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "\u001b[K     |████████████████████████████████| 675kB 7.7MB/s \n",
            "\u001b[K     |████████████████████████████████| 1.1MB 22.1MB/s \n",
            "\u001b[K     |████████████████████████████████| 890kB 50.7MB/s \n",
            "\u001b[K     |████████████████████████████████| 3.8MB 57.9MB/s \n",
            "\u001b[?25h  Building wheel for sacremoses (setup.py) ... \u001b[?25l\u001b[?25hdone\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8-_ExwxYPWdS",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import torch\n",
        "from transformers import XLNetModel\n",
        "import time\n",
        "from datetime import timedelta\n",
        "import os\n",
        "import requests\n",
        "from tqdm.auto import tqdm"
      ],
      "execution_count": 2,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "SD367Vy0PWda",
        "colab_type": "text"
      },
      "source": [
        "<b>2. Set the url location of ProtXLNet and the vocabulary file<b>"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "0A9JPmFTPWdb",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "modelUrl = 'https://www.dropbox.com/s/z0i0z01d2wm19ap/pytorch_model.bin?dl=1'\n",
        "configUrl = 'https://www.dropbox.com/s/to876ivj48wylkj/config.json?dl=1'\n",
        "tokenizerUrl = 'https://www.dropbox.com/s/mvypdtedpuz0yxg/spm_model.model?dl=1'"
      ],
      "execution_count": 3,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9EODL-88PpYC",
        "colab_type": "text"
      },
      "source": [
        "<b>3. Download ProtXLNet models and vocabulary files</b>"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vrrsFy_pPs_7",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "downloadFolderPath = 'models/ProtXLNet/'"
      ],
      "execution_count": 4,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rRpr6xrhPtEW",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "modelFolderPath = downloadFolderPath\n",
        "\n",
        "modelFilePath = os.path.join(modelFolderPath, 'pytorch_model.bin')\n",
        "\n",
        "configFilePath = os.path.join(modelFolderPath, 'config.json')\n",
        "\n",
        "tokenizerFilePath = os.path.join(modelFolderPath, 'spm_model.model')"
      ],
      "execution_count": 5,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "F5k3ZmaoPtIu",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "if not os.path.exists(modelFolderPath):\n",
        "    os.makedirs(modelFolderPath)"
      ],
      "execution_count": 6,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "yteAfTmMsloz",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "def download_file(url, filename):\n",
        "  response = requests.get(url, stream=True)\n",
        "  with tqdm.wrapattr(open(filename, \"wb\"), \"write\", miniters=1,\n",
        "                    total=int(response.headers.get('content-length', 0)),\n",
        "                    desc=filename) as fout:\n",
        "      for chunk in response.iter_content(chunk_size=4096):\n",
        "          fout.write(chunk)"
      ],
      "execution_count": 7,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wD4zUYXOPyAE",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 164,
          "referenced_widgets": [
            "a7b59325aa0540b19139d91e33fb1c0b",
            "20d030310fc54c7dbc2ad67a87a76891",
            "ad2f49ce511647ca8e75a0734980341b",
            "d6cb4d66ca364da1ac13e2f6b830bb54",
            "33192ad6d500451999ba5ba672d2fff5",
            "74e103eeb38d493095acd6dbf4b4788c",
            "e49b133233374e1985361c2ac900ae96",
            "84c9f44c83fc4bc09a2e418bdc95f399",
            "a497f90d042949cea815f05b21d29ef2",
            "06dc2479b6f749c99f8e18c545e29336",
            "15d2b7fe5b4148ea8b7dd984db82ffee",
            "e1d577e3328f4a88b6c71c52db39c8fb",
            "f71ea8387dfa487f943e13fb6833f44f",
            "ce64e85961b94743bf092d30d889dc71",
            "f204f3aec2024cf993c2e60b4e5fe6b6",
            "f228635787c249a297a352531a8e9b94",
            "d5be147b7cd74ad18a97b0fce1228144",
            "a3ccc2e62231425dbdf6350f55c47c7d",
            "d16c310cb93245ba8af3802e57d8d477",
            "93692c6334a34411bcc9319d4303d42e",
            "df1215a1a78c451b8637be18dea4b1dd",
            "48be69984d59411ea99c0dcd599c7b36",
            "8f492bf7ab29454c837579b5e17273c8",
            "b1d69142187c4f38b57bbba9f93d9979"
          ]
        },
        "outputId": "252c10d7-bd70-46f9-ba41-7de4c41dc3ae"
      },
      "source": [
        "if not os.path.exists(modelFilePath):\n",
        "    download_file(modelUrl, modelFilePath)\n",
        "\n",
        "if not os.path.exists(configFilePath):\n",
        "    download_file(configUrl, configFilePath)\n",
        "\n",
        "if not os.path.exists(tokenizerFilePath):\n",
        "    download_file(tokenizerUrl, tokenizerFilePath)"
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.jupyter.widget-view+json": {
              "model_id": "a7b59325aa0540b19139d91e33fb1c0b",
              "version_minor": 0,
              "version_major": 2
            },
            "text/plain": [
              "HBox(children=(FloatProgress(value=0.0, description='models/ProtXLNet/pytorch_model.bin', max=1637757076.0, st…"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.jupyter.widget-view+json": {
              "model_id": "a497f90d042949cea815f05b21d29ef2",
              "version_minor": 0,
              "version_major": 2
            },
            "text/plain": [
              "HBox(children=(FloatProgress(value=0.0, description='models/ProtXLNet/config.json', max=1351.0, style=Progress…"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.jupyter.widget-view+json": {
              "model_id": "d5be147b7cd74ad18a97b0fce1228144",
              "version_minor": 0,
              "version_major": 2
            },
            "text/plain": [
              "HBox(children=(FloatProgress(value=0.0, description='models/ProtXLNet/spm_model.model', max=238192.0, style=Pr…"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "o-jxpHuAPWdf",
        "colab_type": "text"
      },
      "source": [
        "<b>4. Load ProtXLNet Model<b>"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "KmQ9enjpPWdg",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "model = XLNetModel.from_pretrained(modelFolderPath)"
      ],
      "execution_count": 9,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "LpIiYPa_PWdk",
        "colab_type": "text"
      },
      "source": [
        "<b>5. Load the model into the GPU if avilabile and switch to inference mode<b>"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "or_gCqyoPWdl",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')"
      ],
      "execution_count": 10,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "aaaIg_FePWdo",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "model = model.to(device)\n",
        "model = model.eval()"
      ],
      "execution_count": 11,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "4D4Gl1X9PWdr",
        "colab_type": "text"
      },
      "source": [
        "<b>6. Benchmark Configuration<b>"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "gVS7ss_0PWds",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "min_batch_size = 8\n",
        "max_batch_size = 32\n",
        "inc_batch_size = 8\n",
        "\n",
        "min_sequence_length = 64\n",
        "max_sequence_length = 512\n",
        "inc_sequence_length = 64\n",
        "\n",
        "iterations = 10"
      ],
      "execution_count": 12,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "5TtKJPwZPWdz",
        "colab_type": "text"
      },
      "source": [
        "<b>7. Start Benchmarking<b>"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "S-jrnpb0PWd0",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 748
        },
        "outputId": "5754443b-8bfe-41ad-f852-633efad1cc98"
      },
      "source": [
        "device_name = torch.cuda.get_device_name(device.index) if device.type == 'cuda' else 'CPU'\n",
        "\n",
        "with torch.no_grad():\n",
        "    print((' Benchmarking using ' + device_name + ' ').center(80, '*'))\n",
        "    print(' Start '.center(80, '*'))\n",
        "    for sequence_length in range(min_sequence_length,max_sequence_length+1,inc_sequence_length):\n",
        "        for batch_size in range(min_batch_size,max_batch_size+1,inc_batch_size):\n",
        "            start = time.time()\n",
        "            for i in range(iterations):\n",
        "                input_ids = torch.randint(1, 20, (batch_size,sequence_length)).to(device)\n",
        "                results = model(input_ids)[0].cpu().numpy()\n",
        "            end = time.time()\n",
        "            ms_per_protein = (end-start)/(iterations*batch_size)\n",
        "            print('Sequence Length: %4d \\t Batch Size: %4d \\t Ms per protein %4.2f' %(sequence_length,batch_size,ms_per_protein))\n",
        "        print(' Done '.center(80, '*'))\n",
        "    print(' Finished '.center(80, '*'))"
      ],
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "******************* Benchmarking using Tesla P100-PCIE-16GB ********************\n",
            "************************************ Start *************************************\n",
            "Sequence Length:   64 \t Batch Size:    8 \t Ms per protein 0.01\n",
            "Sequence Length:   64 \t Batch Size:   16 \t Ms per protein 0.01\n",
            "Sequence Length:   64 \t Batch Size:   24 \t Ms per protein 0.01\n",
            "Sequence Length:   64 \t Batch Size:   32 \t Ms per protein 0.01\n",
            "************************************* Done *************************************\n",
            "Sequence Length:  128 \t Batch Size:    8 \t Ms per protein 0.02\n",
            "Sequence Length:  128 \t Batch Size:   16 \t Ms per protein 0.02\n",
            "Sequence Length:  128 \t Batch Size:   24 \t Ms per protein 0.02\n",
            "Sequence Length:  128 \t Batch Size:   32 \t Ms per protein 0.02\n",
            "************************************* Done *************************************\n",
            "Sequence Length:  192 \t Batch Size:    8 \t Ms per protein 0.03\n",
            "Sequence Length:  192 \t Batch Size:   16 \t Ms per protein 0.04\n",
            "Sequence Length:  192 \t Batch Size:   24 \t Ms per protein 0.04\n",
            "Sequence Length:  192 \t Batch Size:   32 \t Ms per protein 0.04\n",
            "************************************* Done *************************************\n",
            "Sequence Length:  256 \t Batch Size:    8 \t Ms per protein 0.06\n",
            "Sequence Length:  256 \t Batch Size:   16 \t Ms per protein 0.05\n",
            "Sequence Length:  256 \t Batch Size:   24 \t Ms per protein 0.05\n",
            "Sequence Length:  256 \t Batch Size:   32 \t Ms per protein 0.05\n",
            "************************************* Done *************************************\n",
            "Sequence Length:  320 \t Batch Size:    8 \t Ms per protein 0.07\n",
            "Sequence Length:  320 \t Batch Size:   16 \t Ms per protein 0.07\n",
            "Sequence Length:  320 \t Batch Size:   24 \t Ms per protein 0.08\n",
            "Sequence Length:  320 \t Batch Size:   32 \t Ms per protein 0.08\n",
            "************************************* Done *************************************\n",
            "Sequence Length:  384 \t Batch Size:    8 \t Ms per protein 0.10\n",
            "Sequence Length:  384 \t Batch Size:   16 \t Ms per protein 0.10\n",
            "Sequence Length:  384 \t Batch Size:   24 \t Ms per protein 0.10\n",
            "Sequence Length:  384 \t Batch Size:   32 \t Ms per protein 0.10\n",
            "************************************* Done *************************************\n",
            "Sequence Length:  448 \t Batch Size:    8 \t Ms per protein 0.13\n",
            "Sequence Length:  448 \t Batch Size:   16 \t Ms per protein 0.13\n",
            "Sequence Length:  448 \t Batch Size:   24 \t Ms per protein 0.13\n",
            "Sequence Length:  448 \t Batch Size:   32 \t Ms per protein 0.13\n",
            "************************************* Done *************************************\n",
            "Sequence Length:  512 \t Batch Size:    8 \t Ms per protein 0.13\n",
            "Sequence Length:  512 \t Batch Size:   16 \t Ms per protein 0.14\n",
            "Sequence Length:  512 \t Batch Size:   24 \t Ms per protein 0.13\n",
            "Sequence Length:  512 \t Batch Size:   32 \t Ms per protein 0.14\n",
            "************************************* Done *************************************\n",
            "*********************************** Finished ***********************************\n"
          ],
          "name": "stdout"
        }
      ]
    }
  ]
}